class EmployeeCertificate < ActiveRecord::Base
  extend EmployeeCertificateRepositiory, EmployeeCertificateQuery
  # belongs_to :employee,    class_name: 'Employee'
  belongs_to :certificate, class_name: '::Certificate'

  validates_presence_of :employee_id, :certificate, :valid_from, :number
  validates :certificate, :uniqueness => {:scope => [:employee_id]}
  validate :valid_from_than_now

  state_machine :initial => :normal do

  end

  def employee
    Employee.find(employee_id)
  end


  private

  def valid_from_than_now
    errors.add(:valid_from, "领证时间不能大于当前时间") if valid_from > Time.now.to_date
  end

end
